package com.tsingteng.cosfun.widget.dialog;

import android.app.ActionBar;
import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;

import com.tsingteng.cosfun.R;
import com.tsingteng.cosfun.utils.AppUtils;

//评论选择回复或举报
public class CommSelectDialog extends Dialog {
    public CommSelectDialog(Context context) {
        super(context);
    }

    public CommSelectDialog(Context context, int theme) {
        super(context, theme);
    }

    public static class Builder {
        private OnItemClickListener onItemClickListener;

        private View layout;
        private CommSelectDialog dialog;
        private String commId;
        private String userId;
        private String opusId;
        private int position;

        public Builder(Context context, Activity activity) {
            //这里传入自定义的style，直接影响此Dialog的显示效果。style具体实现见style.xml
            dialog = new CommSelectDialog(context, R.style.commselectDialog);
            LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            layout = inflater.inflate(R.layout.comm_select_dialog, null);
            dialog.addContentView(layout, new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT));
        }

        public Builder setItemClickListener(OnItemClickListener listener) {
            this.onItemClickListener = listener;
            return this;
        }

        public Builder setMessage(int position, String opusId, String commId, String userId) {
            this.commId = commId;
            this.userId = userId;
            this.opusId = opusId;
            this.position = position;
            return this;
        }

        /**
         * 创建单按钮对话框
         *
         * @return
         */
        public CommSelectDialog createDialog() {
            layout.findViewById(R.id.comm_select_dialog_answer).setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (onItemClickListener != null) {
                        onItemClickListener.onAnswer(position, opusId, commId, userId);
                        dialog.dismiss();
                    }
                }
            });
            layout.findViewById(R.id.comm_select_dialog_report).setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (onItemClickListener != null) {
                        onItemClickListener.onReport(position, opusId, commId, userId);
                        dialog.dismiss();
                    }
                }
            });

            create();
            return dialog;
        }

        /**
         * 单按钮对话框和双按钮对话框的公共部分在这里设置
         */
        private void create() {
            dialog.setContentView(layout);
            dialog.setCancelable(true);     //用户可以点击手机Back键取消对话框显示
            dialog.setCanceledOnTouchOutside(true);        //用户不能通过点击对话框之外的地方取消对话框显示
        }

    }


    public interface OnItemClickListener {
        void onAnswer(int position, String opusId, String commId, String userId);

        void onReport(int position, String opusId, String commId, String userId);
    }
}
